<template>
  <div class="app-wrapper">
    <router-view v-slot="{ Component }">
      <transition name="fade" mode="out-in">
        <component :is="Component" />
      </transition>
    </router-view>
    <!-- 只在特定页面显示底部导航 -->
    <Bottom2 v-if="showBottom"></Bottom2>
  </div>
</template>

<script setup>
import { ref, computed, watch } from 'vue';
import { useRoute } from 'vue-router';
import Bottom2 from "./components/Bottom2.vue";
import { getToken } from "@/utils/token";

const route = useRoute();
const isLoggedIn = ref(!!getToken());

// 定义需要显示底部导航的页面路由名称
const pagesWithBottom = ['mine', 'detail', 'chart', 'asset'];

// 计算是否显示底部导航
const showBottom = computed(() => {
  return isLoggedIn.value && pagesWithBottom.includes(route.name);
});

// 监听路由变化，更新登录状态
watch(route, () => {
  isLoggedIn.value = !!getToken();
});
</script>

<style>
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* 页面过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 全局样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: #f5f5f5;
  color: #333;
}
</style>